#pragma once

#include "MessageQueue.h"
#include "jsi_executor/JSIExecutor.h"
#include "jsi_executor/ModuleRegistry.h"

namespace bridge {
using namespace jsiexecutor;

class NativeToJSBridge {
 public:
  NativeToJSBridge(std::shared_ptr<Runtime> runtime, std::shared_ptr<ModuleRegistry> registry,
                   std::shared_ptr<MessageQueue> jsQueue);

  void initializeRuntime();

  // this only support sync func, cause Dynamic doesnt support function type, test only
  void callFunction(const std::string&& module, const std::string&& method, Dynamic&& args);

  void loadBundle(const std::string&& buffer, const std::string&& sourceUrl);

  void invokeCallback(unsigned int callbackId);

 private:
  void runOnExecutorQueue(std::function<void(JSIExecutor*)>&& task) noexcept;
  std::shared_ptr<MessageQueue> jsQueue_;
  std::unique_ptr<JSIExecutor> jsiExecutor_;
};
}  // namespace bridge